package com.wlyuan.index.domain.source.adapter;

import com.wlyuan.index.api.dto.QuotationIndexDTO;
import com.wlyuan.quotation.vo.quotation.QuotationDetailVO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

/**
 * @author yuanjie
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class QuotationAdapter extends QuotationIndexDTO {

    @Mapper
    public interface Assembler {
        QuotationIndexDTO translate(QuotationDetailVO source);

        void assemble(@MappingTarget QuotationIndexDTO quotation, QuotationIndexDTO source);
    }

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);


    public QuotationAdapter(QuotationIndexDTO index) {
        ASSEMBLER.assemble(this, index);
    }

    public static QuotationIndexDTO translate(QuotationDetailVO source) {
        return ASSEMBLER.translate(source);
    }
}
